package adapter.caminhoneiro;

import java.util.List;

import tcc.caminhoneiro.R;

import entidade.caminhoneiro.Frete;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import apresentacao.caminhoneiro.Fragment_Meu_Frete;
import apresentacao.caminhoneiro.Fragment_Meus_Fretes;
import apresentacao.caminhoneiro.Fragment_Meus_Fretes_Atualizar;

public class FretesAdapter extends BaseAdapter{
	private  FragmentActivity context;
	private  List<Frete> values;
	
	public FretesAdapter(FragmentActivity context, List<Frete> values){
		this.context = context;
		this.values = values;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return values.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return values.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		    convertView = inflater.inflate(R.layout.frete_view, null);
		    
		    TextView produto = (TextView) convertView.findViewById(R.id.frete_view_produto_content);
		    TextView from = (TextView) convertView.findViewById(R.id.frete_view_from);
		    TextView to = (TextView) convertView.findViewById(R.id.frete_view_to);
		    TextView status = (TextView) convertView.findViewById(R.id.frete_view_info_status);
		    //ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
		    
		    final Frete frete_linha = values.get(position);
		    
		    produto.setText(" "+frete_linha.getProduto().getNome());
		    from.setText(" "+frete_linha.getEndereco_Origem().getCompleto());
		    to.setText(" "+frete_linha.getEndereco_Destino().getCompleto());
		    status.setText(" "+frete_linha.getStatus());
		    
		    if (position%2 == 0) convertView.setBackgroundColor(Color.WHITE);
		    else convertView.setBackgroundColor(Color.CYAN);
		    
		    convertView.setOnClickListener(new View.OnClickListener() {
	            @Override
	            public void onClick(View view) {
	            	Bundle bundle = new Bundle();
	            	bundle.putSerializable("frete", frete_linha);
	    			Fragment_Meu_Frete result = new Fragment_Meu_Frete();
	    			result.setArguments(bundle);
	    			context.getSupportFragmentManager().beginTransaction().addToBackStack("FragFrete").replace(R.id.menu_principal_llFragment, result).commit();
	            }
	        });
		    return convertView;
	}

}
